package com.jdl.iscm.page;

import com.jdl.iscm.common.CommonCmpt;
import com.jdl.iscm.common.DimensionCmpt;
import com.jdl.iscm.common.JoinUtil;
import com.jdl.iscm.entity.enums.StockParamEnum;
import com.jdl.iscm.entity.excel.RsSimpExcel;
import com.jdl.iscm.entity.proterties.ReplenishXpathProperties;
import com.jdl.iscm.page.interfaces.ManualAddInterface;
import org.openqa.selenium.WebDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: Ran
 * @Date: 2021/8/24
 **/
@Component
public class RsSimpPage implements ManualAddInterface<RsSimpExcel> {

    @Autowired
    private CommonCmpt commonCmpt;

    @Autowired
    private DimensionCmpt dimensionCmpt;

    /**
     * 手工添加
     *
     * @param webDriver
     * @param xpathProperties
     */
    @Override
    public void manualAdd(WebDriver webDriver, ReplenishXpathProperties xpathProperties) {
        commonCmpt.click(webDriver, xpathProperties.getConfigAdd());
    }

    /**
     * 手工添加设置
     *
     * @param webDriver
     * @param xpathProperties
     * @param rsSimpExcel
     */
    @Override
    public void manualAddSetting(WebDriver webDriver, ReplenishXpathProperties xpathProperties, RsSimpExcel rsSimpExcel) {
        //先取消勾选
        commonCmpt.click(webDriver, xpathProperties.getConfigDimSku());
        //1、设置场景
        List<String> scenesXpath = rsSimpExcel.getSceneList().stream().map(scene -> JoinUtil.textJoin(xpathProperties, scene)).collect(Collectors.toList());
        commonCmpt.drpDwnClick(webDriver, xpathProperties.getConfigSceneInput(), scenesXpath);
        //2、参数设置维度
        String type = rsSimpExcel.getType();
        String r = rsSimpExcel.getR();
        String s = rsSimpExcel.getS();
        commonCmpt.click(webDriver, JoinUtil.containsJoin(xpathProperties, type));
        //3、根据维度设置 R S
        if (StockParamEnum.DaySet.code().equals(rsSimpExcel.getType())) {
            commonCmpt.input(webDriver, xpathProperties.getConfigStrategyRInput1(), r);
            commonCmpt.input(webDriver, xpathProperties.getConfigStrategySInput1(), s);
        } else if (StockParamEnum.UnitSet.code().equals(rsSimpExcel.getType())) {
            commonCmpt.input(webDriver, xpathProperties.getConfigStrategyRInput2(), r);
            commonCmpt.input(webDriver, xpathProperties.getConfigStrategySInput2(), s);
        }
        //4、设置维度
        dimensionCmpt.setDimValueByDimKey(webDriver, xpathProperties, rsSimpExcel.getDimensionMap());
    }

    /**
     * 手工添加提交
     *
     * @param webDriver
     * @param xpathProperties
     */
    @Override
    public void manualAddSubmit(WebDriver webDriver, ReplenishXpathProperties xpathProperties) {
        commonCmpt.click(webDriver, xpathProperties.getConfigSubmit());
    }
}
